<?php

namespace Modules\Inventory\Repository;

use Modules\Inventory\Models\InventoryPlanDiff;

class InventoryPlanDiffRepository
{

    static public function getList($params){

        $builder = self::getWhere($params);

        $limit = isset($request['limit']) ? $request['limit'] : 100;

        $list = $builder->orderBy('id','desc')->with(['material','wms'])->paginate($limit)->toArray();

        return $list;

    }

    static public function getWhere($params){
        $builder = new InventoryPlanDiff();

        $canSearchFields = $builder->getFields();

        foreach ($params as $key => $val){

            if(!in_array($key,$canSearchFields) || $val == ''){
                continue;
            }

            $builder = $builder->where($key,$val);

        }

        return $builder;

    }

}
